/**
 * Created by wanende on 2017/7/3.
 */
var _GLOBE_DATA = (function () {
    var data = {};
    return function (key, val) {
        if (val === undefined) {
            return data[key];
        }
        else {
            return data[key] = val;
        }
    }
})();

(function () {
    //路径
    _GLOBE_DATA("basePathFn",function () {
        var basePath = "";
        var h = window.location.protocol;
        var u = window.location.hostname;
        var p = window.location.port;
        if (p && p != "") {
            p = ":" + p;
        }
        basePath = h + "//" + u + p + "/ims";
        return basePath;
    });
   //打印日志
    _GLOBE_DATA('HOPLog', function (title, msg) {
        if (_GLOBE_DATA("HOP_IS_DEBUG")) {
            // console.log(title + ":" + JSON.stringify(msg));
        }
    });
    //加载js文件
    _GLOBE_DATA("loadJS",function (jsFiles, pageScript) {
        var i;
        for(i = 0; i<jsFiles.length;i++){

            var body = document.getElementsByTagName('body')[0];
            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.async = false;
            script.src = jsFiles[i];
            body.appendChild(script);
        }

        if (pageScript) {
            var body = document.getElementsByTagName('body')[0];
            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.async = false;
            script.src = pageScript;
            body.appendChild(script);
        }
    });

//加载css文件
    _GLOBE_DATA("loadCSS",function (cssFile, end, callback) {

        var cssArray = {};

        if (!cssArray[cssFile]) {
            cssArray[cssFile] = true;

            if (end == 1) {
                for(i = 0; i<cssFile.length;i++){
                    var head = document.getElementsByTagName('head')[0];
                    var s = document.createElement('link');
                    s.setAttribute('rel', 'stylesheet');
                    s.setAttribute('type', 'text/css');
                    s.setAttribute('href', cssFile[i]);

                    s.onload = callback;
                    head.appendChild(s);
                }

            } else {
                for(i = 0; i<cssFile.length;i++){
                    var head = document.getElementsByTagName('head')[0];
                    var style = document.getElementById('main-style');

                    var s = document.createElement('link');
                    s.setAttribute('rel', 'stylesheet');
                    s.setAttribute('type', 'text/css');
                    s.setAttribute('href', cssFile[i]);
                    s.onload = callback;
                    head.insertBefore(s, style);
                }
            }

        } else if (callback) {
            callback();
        }
    });
    _GLOBE_DATA("createURL",function(url,param,currentPage,showCount/*链接和参数*/){
        if(currentPage==null){
            currentPage = 1
        }
        if(showCount==null){
            showCount = 10
        }
        var _url = url;
        var _param = "?"
        $("#searchbox input[type='text'],#searchbox input[type='hidden']").each(function(){
            _param += $(this).attr("name")+"="+$(this).val()+"&";
        });
        _param+='currentPage='+currentPage;
        _param+='&showCount='+showCount;
        // _param = _param.substring(0,_param.length-1);
        _url += _param;
        return encodeURI(encodeURI(_url));
    });
    _GLOBE_DATA("reLoadPageParam",function(url){
        var  res = url;
        $("#iframeContent").empty();
        $("#iframeContent").load(res);
    });
    _GLOBE_DATA("autoHeight",function(){
        var  _height = $(document).height();
        var _contentHeight = _height-($(".header").height()+$("footer").height()+$(".layui-breadcrumb-bbs").height());
        // console.log(_height+"     "+_contentHeight);
        $(".content-container-view,.content-container").css("min-height",_contentHeight+"px");
    });

    _GLOBE_DATA("autoMianHeight",function(){
        var _height = $(document).height();
        var _contentHeight = _height-($(".header").height()+$("footer").height()+22);
        // console.log(_height+"     "+_contentHeight);
        $(".content-container").height(_contentHeight+"px");
    });
    _GLOBE_DATA("sysautoHeight",function(){
        // var _heightOuter = $(document.body).outerHeight(true);
        var  _heightOuter = $(document.body).height();
        var  _height = $(document).height();
        var _contentHeight = _height-($(".header").height()+$("footer").height());
        var _contentHeightOuter = _heightOuter-($(".header").height()+$("footer").height());
        // // console.log(_height+"     "+_contentHeight);
        $(".content-container").css("min-height",_contentHeight+"px");
        // $("#topUl").height($(".content-container").height()+20);
    });
    document.onkeydown = function(event) {
        var target, code, tag;
        if (!event) {
            event = window.event; //针对ie浏览器
            target = event.srcElement;
            code = event.keyCode;
            if (code == 13) {
                tag = target.tagName;
                if (tag == "TEXTAREA") { return true; }
                else { return false; }
            }
        }
        else {
            target = event.target; //针对遵循w3c标准的浏览器，如Firefox
            code = event.keyCode;
            if (code == 13) {
                tag = target.tagName;
                if (tag == "INPUT") { return false; }
                else { return true; }
            }
        }
    };



})();